package command;

import java.awt.Component;
import javax.swing.JFileChooser;

import guimessage.FileUpload;
import controller.Contact;
import controller.GUIController;

public class SendFile implements ICommand {

	protected GUIController guicontroller;
	protected Component parent;
	protected Contact contact;
	
	public SendFile(Component parent, Contact c) {
		this.parent = parent;
		this.contact = c;
		this.guicontroller = GUIController.getInstance();
	}

	public void execute() {
		// il va falloir ouvrir une fenêtre ici pour demander quel fichier on veut envoyer
		
		JFileChooser chooser = new JFileChooser();
	    int returnVal = chooser.showOpenDialog(parent);
	    if(returnVal == JFileChooser.APPROVE_OPTION) {
	       //System.out.println("You chose to open this file: " + chooser.getSelectedFile().getPath() + " with a size of " + chooser.getSelectedFile().length() );
	       
	       guicontroller.messages.add( new FileUpload(contact, chooser.getSelectedFile().getName(), chooser.getSelectedFile().getPath(), (int) chooser.getSelectedFile().length()) );
	    }
	}

}
